﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Coupon_Manager_ActionLayer;

namespace Coupon_Manager_WebGUI.Modules.CouponEntry
{
    public partial class CouponEntry : System.Web.UI.UserControl
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            using (var action = new CouponAction(@"Data Source=cookstasoftware.com;Initial Catalog=CouponManagerDev;Persist Security Info=True;User ID=cookstaDev;Password=asdfjkl456"))
            {
                gvCoupons.DataSource = action.GetCoupons();
                gvCoupons.DataBind();
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                using (var action = new CouponAction(@"Data Source=cookstasoftware.com;Initial Catalog=CouponManagerDev;Persist Security Info=True;User ID=cookstaDev;Password=asdfjkl456"))
                {
                    action.InsertCoupon(txtUPC.Text, txtDescription.Text, Convert.ToDecimal(txtDiscount.Text),
                                        Convert.ToInt32(txtPurchaseQuantity.Text), Convert.ToInt32(ddlCategory.SelectedValue),
                                        Convert.ToDateTime(txtExpirationDate.Text));
                    gvCoupons.DataSource = action.GetCoupons();
                    gvCoupons.DataBind();
                }
            }
            catch (Exception)
            {
            }
        }
    }
}